Date.prototype.format = function(format){ 
	var o = { 
		"M+" : this.getMonth()+1, //month 
		"d+" : this.getDate(), //day 
		"h+" : this.getHours(), //hour 
		"m+" : this.getMinutes(), //minute 
		"s+" : this.getSeconds(), //second 
		"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
		"S" : this.getMilliseconds() //millisecond 
	}; 
	if(/(y+)/.test(format)) { 
		format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
	} 
	for(var k in o) { 
		if(new RegExp("("+ k +")").test(format)) { 
			format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
		} 
	} 
	return format; 
}
String.prototype.yyMMdd=function(){
	if(this.indexOf("-"))
	  return new Date(this.replace(/-/g,"/"));
	else
	  return new Date(this);
}
// 清空全部空格
String.prototype.TrimAll=function(){
return this.replace(/\s/g,"");
} 
// 清空左右空格
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g,"");
} 
String.prototype.replaceAll = function(s1,s2) { 
    return this.replace(new RegExp(s1,"gm"),s2); 
}
//计算字节长度
String.prototype.lenReg = function(){
　　var byteLen=0,len=this.length; 
　　　　for(var i=0; i<len; i++){ 
　　　　　　if(this.charCodeAt(i)>255){ 
　　　　　　　　byteLen += 2; 
　　　　　　} 
　　　　　　else{ 
　　　　　　　　byteLen++; 
　　　　　　} 
　　　　} 
　　　　return byteLen; 
}
//截取字符串，超出字节长度用...省略
String.prototype.ellipsis = function(leng){
	if(isNaN(leng)){
		return this;
	}
	if(this.lenReg() > leng){
		leng = leng - 3;
		var byteLen=0,len=this.length; 
		for(var i=0; i<len; i++){ 
			if(this.charCodeAt(i)>255){ 
				byteLen += 2; 
			}else{ 
				byteLen++; 
			} 
			if(byteLen > leng){
				return this.substring(0,i) + "...";
			}
		} 
	}
	return this;
}
//给非IE浏览器的元素添加模拟单击事件
if(!document.all){
	Element.prototype.click = function(){
		var evt = document.createEvent("MouseEvents");  
		evt.initEvent("click", true, true);  
		this.dispatchEvent(evt);  
	}
}


function setcookie(name,value,Days){  
    if(!Days || isNaN(Days)) Days = 30;  
    var exp  = new Date();  
    exp.setTime(exp.getTime() + Days*24*60*60*1000);  
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();  
}  
  
function getcookie(name){  
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));   
    if(arr != null){  
        return unescape(arr[2]);  
    }else{  
        return "";  
    }  
}  
  
function delcookie(name){  
    var exp = new Date();   
    exp.setTime(exp.getTime() - 1);  
    var cval=getCookie(name);  
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();  
} 
/** 请输入
 * text:默认内容;style:默认内容样式;first:是否点击一次清空
 */
$.fn.pleaseInput = function (text,style,first){
	if(this.length == 0){ return this };
	var pleace = typeof text=="string"?text:"请输入";
	var obj = this[0];
	if(obj.oStyle){
		for(var key in obj.oStyle){
			$(this).css(key,obj.oStyle[key]);
		}
	}
	obj.oStyle = {};
	if(typeof style == 'boolean'){
		first = style;
	}
	if(typeof style == "string"){
		var color = style;
		if(color.indexOf("#")<0){
			color = "#"+color;
		}
		style = {};
		style["color"] = color;
	}
	if(typeof style == "object"){
		for(var key in style){
			obj.oStyle[key] = this.css(key);
		}
	}
	if(this.val() == "" || this.val() == pleace){
		this.val(pleace);
		for(var key in style){
			this.css(key,style[key]);
		}
	}
	var focus = function (){
		if(obj.value == pleace){
			obj.value = "";
		}
		for(var key in style){
			$(obj).css(key,obj.oStyle[key]);
		}
	}
	var blur = function (){
		if(obj.value == ""){
			obj.value = pleace;
			for(var key in style){
				$(obj).css(key,style[key]);
			}
		}
	}
	this[0].change = function(){
		if(obj.value == pleace){
			obj.value = "";
		}
		for(var key in style){
			$(obj).css(key,obj.oStyle[key]);
		}
	}
	this.unbind(".pleaceInput");
	this.bind("focus.pleaceInput",focus);
	this.bind("keypress.pleaceInput",this[0].change);
	if(first != true){
		this.bind("blur.pleaceInput",blur);
	}
	/*
	 * 是否输入值,isClear=true：如果没有输入则清空内容
	 */
	this[0].isInput = function(isClear){
		if(this.value != pleace){
			return true;
		}else{
			if(isClear == true){
				this.value = '';
			}else{
				this.value = pleace;
			}
		}
	}
	return this;
}


//判断滚动条是否滚动底了
function reachBottom(){
    var scrollTop = 0;
    var clientHeight = 0; 
    var scrollHeight = 0;
 
    if(document.documentElement && document.documentElement.scrollTop) {  
        scrollTop = document.documentElement.scrollTop;  
    } else if (document.body) {  
		scrollTop = document.body.scrollTop;  
    }  
	clientHeight = document.documentElement.clientHeight;
    scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
    if(scrollTop + clientHeight > scrollHeight - 400) {  
        return true;  
    } else {
        return false; 
    }
}

var prefix = '';
var namespace_arrys = ['pf', 'im', 'os', 'p','cts'];
 //当前URL是否存在struts命名空间
function isIncludeNameSpace(field){
 	for(var i=0; i<namespace_arrys.length; i++){
 		if(field.indexOf('\/' + namespace_arrys[i] +  '\/') != -1){
 			return true;
 		}
 	}
 	return false;
}

$(function(){
	//让IE6 a链接悬浮切换图片不闪动
	if($.browser.msie && $.browser.version.indexOf("6") >= 0){
		try {
			document.execCommand("BackgroundImageCache", false, true);         
		} catch(err) {}
	}
	
	if(!isIncludeNameSpace(document.URL)){
		prefix = 'cts/';
	}
});

function changeChecked(obj){
	if($(obj).attr("class")=="checked"){
		$(obj).removeClass("checked");
		$(obj).addClass("unchecked");
	}else{
		$(obj).removeClass("unchecked");
		$(obj).addClass("checked");
	}
}